using BackOffice.Domain.Entities.App;

namespace Backoffice.Domain.Entities.App;
public class AppFile : EntityBase
{
    public string FileName      { get; private set; }
    public long   FileSize      { get; private set; }
    public string FileExtension { get; private set; }
    public string MimeType      { get; private set; }
    public string RelativePath  { get; private set; }
    public string? Description  { get; private set; }

    public Guid? FolderId       { get; private set; }

    /* 导航属性 */
    public virtual AppFolder?          Folder    { get; private set; }
    public virtual List<AppFileShare>  Shares    { get; private set; } = new();
    public virtual List<AppFileAcl>    Acls      { get; private set; } = new();

  #region ctor
#pragma warning disable CS8618 // 在退出构造函数时，不可为 null 的字段必须包含非 null 值。请考虑添加 "required" 修饰符或声明为可为 null。
  private AppFile() { }
#pragma warning restore CS8618 // 在退出构造函数时，不可为 null 的字段必须包含非 null 值。请考虑添加 "required" 修饰符或声明为可为 null。

  public AppFile(string fileName,
                   long   fileSize,
                   string fileExtension,
                   string mimeType,
                   string relativePath,
                   Guid?  folderId   = null,
                   string? description = null)
    {
        FileName      = fileName;
        FileSize      = fileSize;
        FileExtension = fileExtension.ToLowerInvariant();
        MimeType      = mimeType;
        RelativePath  = relativePath;
        FolderId      = folderId;
        Description   = description;
    }
    #endregion

    #region behaviors
    public void Rename(string newName) => FileName = newName;
    public void Move(Guid? newFolderId) => FolderId = newFolderId;
    public void UpdateDesc(string? desc) => Description = desc;
    #endregion
}